<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name = "format-detection" content = "telephone=no">
		<meta name="viewport"  content="width=device-width,user-scalable=no">
		<title>李陈毅微信支付8</title>
		<style>
			button {width: 50%; height 300px;}
		</style>
		<script type="application/javascript">
			var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
			function generateMixed(n) {
			     var res = "";
			     for(var i = 0; i < n ; i ++) {
			         var id = Math.ceil(Math.random()*35);
			         res += chars[id];
			     }
			     return res;
			}
			
			function ready() {
				if(typeof WeixinJSBridge == "undefined") {
					if(document.addEventListener) {
						document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
					} else if(document.attachEvent) {
						document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
						document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
					}
				} else {
					onBridgeReady();
				}
			}
			
			function onBridgeReady() {
				var timeStamp = (Date.parse(new Date())/1000).toString();//时间戳一定要是字符串

				var nonceStr = generateMixed(32);
				WeixinJSBridge.invoke('getBrandWCPayRequest', {
						"appId": "wxf10dd27fe97945c4", //公众号名称，由商户传入     

						"timeStamp": timeStamp, //时间戳，自1970年以来的秒数     

						"nonceStr": nonceStr, //随机串     

						"package": "prepay_id=u802345jgfjsdfgsdg888",
						"signType": "MD5", //微信签名方式：     

						"total_fee": "100",	//订单金额

						"paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 

					}, function(res) {
					alert(JSON.stringify(res));
					if(res.err_msg == "get_brand_wcpay_request:ok") {} // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 

				});
			}
		</script>
	</head>
	<body>
		<button onclick="ready()">请点击</button>
	</body>
</html>